<?php
class Exts_Db_Table_Row_AuditableRow extends Exts_Db_Table_Row_Abstract{ 
	protected $_audited = false;
	
	public function audit($userId) {
		if ($this->isTransient()){
			$this->create_date = new Zend_Db_Expr( 'NOW()' );
			$this->create_user =$userId;  
		}
		$this->update_date = new Zend_Db_Expr( 'NOW()' );
		$this->update_user =$userId;
		$this->_audited = true;
		return $this;
	}
	
	public function getCurrentUser () {
		return $this->getTable()->getCurrentUser();
	}
	
	public function save(){		
		
		if (!$this->_audited){
			$user = $this->getCurrentUser();
			if(!$user){
				throw new Exts_Exception("La fila necesita acceder al usuario actual!");
			}
			$this->audit($user->user_id);
		}
		return parent::save();
	}
}